{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "d7a14bfa-15fb-4c08-88a2-fa27c16ed8df",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "F:\\programData\\conda\\env\\ChatGLM2-6B\\lib\\site-packages\\numpy\\_distributor_init.py:30: UserWarning: loaded more than 1 DLL from .libs:\n",
      "F:\\programData\\conda\\env\\ChatGLM2-6B\\lib\\site-packages\\numpy\\.libs\\libopenblas.FB5AE2TYXYH2IJRDKGDGQ3XBKLKTF43H.gfortran-win_amd64.dll\n",
      "F:\\programData\\conda\\env\\ChatGLM2-6B\\lib\\site-packages\\numpy\\.libs\\libopenblas64__v0.3.23-246-g3d31191b-gcc_10_3_0.dll\n",
      "  warnings.warn(\"loaded more than 1 DLL from .libs:\"\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "torch.Size([8, 8])"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import torch\n",
    "from torch import nn\n",
    "def comp_conv2d(conv2d,x):\n",
    "    x = x.reshape((1,1) + x.shape)\n",
    "    y = conv2d(x)\n",
    "    return y.reshape(y.shape[2:])\n",
    "\n",
    "conv2d = nn.Conv2d(1,1,kernel_size=3,padding=1)\n",
    "x = torch.rand(size=(8,8))\n",
    "comp_conv2d(conv2d,x).shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "f415f156-1fd1-4ebd-bf1d-1afdcd4e1d3e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "torch.Size([8, 8])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "conv2d = nn.Conv2d(1,1,kernel_size=(5,3),padding=(2,1))\n",
    "x = torch.rand(size=(8,8))\n",
    "comp_conv2d(conv2d,x).shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "10c142db-0ceb-4508-8431-294c86d60a62",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "torch.Size([2, 2])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#6.3.2. 步幅\n",
    "conv2d = nn.Conv2d(1,1,kernel_size=(3,5),padding=(0,1),stride=(3,4))\n",
    "comp_conv2d(conv2d,x).shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1ea7a977-cdf3-4c1c-bbb9-b24bc06c2f02",
   "metadata": {},
   "outputs": [],
   "source": [
    "#输入图片大小 W×W\n",
    "#卷积核大小 F×F\n",
    "#步长 S\n",
    "#padding的像素数 P\n",
    "#于是我们可以得出计算公式为：\n",
    "#N = (W − F + 2P )/S+1"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.17"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
